const app = getApp()

var utilMd5 = require('./md5.js');
Page({
  data: {
    accountName:"",
    password:""
  },
  newchange(){
    console.log(app.globalData)
    var that = this;
    if (!this.data.accountName){
      wx.showToast({
        title: '请输入账号',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    if (!this.data.password) {
      wx.showToast({
        title: '请输入密码',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    wx.showLoading({
      title: '加载中',
    });
    wx.request({
      url: app.globalData.Url+"/emergency/v1.0/user/login", //仅为示例，并非真实的接口地址
      data: {
        userAccount: this.data.accountName,
        userPasswd: utilMd5.hexMD5(this.data.password)
      },
      method:"post",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data)
          wx.hideLoading();
         if(res.data.meta.success){
           wx.showToast({
             title: "登录成功",
             icon: 'success',
             duration: 1000
           })
           wx.setStorage({
                key: "user",
                data: JSON.stringify(res.data.data)
           })
           wx.switchTab({
               url: '../index/index'
          });
         }else{
           wx.showToast({
             title: res.data.meta.message,
             icon: 'none',
             duration: 1000
           })
         }
      }
    })
    
  },
  inputTyping: function (e) {
    this.setData({
      accountName: e.detail.value
    });
  },
  inputpass: function (e) {
    this.setData({
      password: e.detail.value
    });
  }
})
